package com.fanqwz.kotlinmvvm

//import com.firefly1126.permissionaspect.PermissionCheckSDK
import com.fanqwz.kotlinmvvm.common.util.log.AndroidRollingFileAppender
import com.fanqwz.kotlinmvvm.di.DaggerAppComponent
import com.fanqwz.kotlinmvvm.di.module.NetWorkModule
import dagger.android.AndroidInjector
import dagger.android.support.DaggerApplication
import io.reactivex.plugins.RxJavaPlugins
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 * Created by fanqwz on 2017/10/11.
 */
class MyApplication : DaggerApplication() {
    override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
        return DaggerAppComponent.builder()
                .application(this)
//                .AppModule(AppModule(this))
                .networkModule(NetWorkModule())
                .build()
    }

    val logger: Logger by lazy { LoggerFactory.getLogger(this::class.java) }

    override fun onCreate() {
        super.onCreate()
        logger.debug("oncreate")
        AndroidRollingFileAppender.addToRootLogger(BuildConfig.APPLICATION_ID, filesDir.absolutePath)
        RxJavaPlugins.setErrorHandler { logger.error("RxJava unhandled: ", it) }
//        PermissionCheckSDK.init(this)
//        PermissionCheckSDK.addCheckPermissionItem(CheckPermissionItem item)
    }

    override fun onTerminate() {
        logger.debug("onTerminate")
        super.onTerminate()
    }
}